<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common/include :: header('新增客户')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-customer-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">客户名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="name" id="customerName" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">客户年龄：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="age" id="customerAge" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">客户电话：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="phone" id="customerPhone" required>
            </div>
        </div>
    </form>
</div>
<th:block th:include="common/include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "/business/customer";
    $("#form-customer-add").validate({
        onkeyup: false,
        rules: {
            name: {
                required: true,
                rangelength: [2, 10]

            },
            age: {
                required: true,
                digits: true,
                range: [1, 130]
            },
            phone: {
                required: true,
                rangelength: [11, 11],
                digits: true,
                remote: {
                    url: prefix + "/checkPhoneUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        phone: function () {
                            return $.common.trim($("#customerPhone").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            }
        },
        messages: {
            name: {
                required: "姓名必填",
                rangelength: "姓名为2~10个汉字"
            },
            age: {
                required: "年龄必填",
                digits: "年龄必须为数字",
                range: "年龄在1~130之间"
            },
            phone: {
                required: "手机号必填",
                rangelength: "手机号为11位",
                digits: "手机号必须全部为数字",
                remote: "手机号已存在"
            }
        },
        focusCleanup: true
    });

    // $("#form-customer-add").validate({
    //     onkeyup: false,
    //     rules:{
    //         name: {
    //             required: true,
    //             rangelength: [2,10]
    //         },
    //         phone: {
    //             required: true,
    //             rangelength: [11,11],
    //             digits: true,
    //             remote:{
    //                 url: prefix+"/checkPhoneUnique",
    //                 type: "post",
    //                 dataType: "json",
    //                 data: {
    //                     "phone": function (){
    //                         return $.common.trim($("#customerPhone").val());
    //                     }
    //                 },
    //                 dataFilter: function (data, type) {
    //                     return $.validate.unique(data);
    //                 }
    //             }
    //         },
    //         age: {
    //             required: true,
    //             digits: true,
    //             range: [1,130]
    //         }
    //     },
    //     messages:{
    //         name: {
    //             required: "姓名必填",
    //             rangelength: "姓名在2-10个汉字"
    //         },
    //         phone: {
    //             required: '手机号必填',
    //             rangelength: "手机号为11位",
    //             digits: "手机号必须全部为数字",
    //             remote: "手机号码已存在，请重新填写"
    //         },
    //         age: {
    //             required: "年龄必填",
    //             digits: "年龄必须为数字",
    //             range: "年龄范围为1到130岁之间"
    //         }
    //     },
    //     focusCleanup: true
    // });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-customer-add').serialize());
        }
    }
</script>
</body>
</html>
